
package view.panels.graphical.drawables;

import jgf.Attribute;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Line2D;
import jgf.beans.ArcBean;

/**
 *
 * @author Marcos Garcia Ortega <a href="mailto:thiamath@gmail.com">&lt;thiamath@gmail.com&gt;</a>
 */
public class DrawArc implements Drawable, Interactive{

	//TODO Add support to show attributes in any way

	protected Line2D.Float shape;
	protected Color color = Color.BLACK;

	protected Integer from=-1;
	protected Integer to=-1;
	protected int index;
	protected Attribute showedAttribute;

	protected String label;
	protected String tag;

	protected boolean selected = false;

	public DrawArc(Point x, Point y){
		shape = new Line2D.Float();
		shape.setLine(x, y);
	}

	public DrawArc(ArcBean arc){
		shape = new Line2D.Float();
		label = arc.getLabel();
		if(!arc.getAttributes().isEmpty())
			showedAttribute = arc.getAttributes().get(0);
		if(showedAttribute != null)
			tag = showedAttribute.getName() + "=" + showedAttribute.getValue();
		from = arc.getFromId();
		to = arc.getToId();
		index = arc.getId();
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Attribute getShowedAttribute() {
		return showedAttribute;
	}

	public void setShowedAttribute(Attribute attributeShowed) {
		this.showedAttribute = attributeShowed;
		if(showedAttribute != null)
			tag = showedAttribute.getName() + "=" + showedAttribute.getValue();
	}

	public Integer getId() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public void setOrigin(float x, float y){
		shape.x1 = x;
		shape.y1 = y;
	}

	public void setOrigin(Point origin){
		setOrigin(origin.x, origin.y);
	}

	public void setEnd(float x, float y){
		shape.x2 = x;
		shape.y2 = y;
	}
	
	public void setEnd(Point end){
		setEnd(end.x, end.y);
	}

	public void setColor(Color color){
		this.color = color;
	}
	
	public void display(Graphics2D g) {
		//Set
		String cat = this.getTag();

		//Paint
		g.setColor(color);
		g.draw(shape);
		if(cat != null)
		g.drawString(cat, (float)shape.getBounds2D().getCenterX(), (float)shape.getBounds2D().getCenterY());

	}

	public Line2D getShape() {
		return shape;
	}

	public boolean isSelected() {
		return selected;
	}

	public void select() {
		selected = true;
	}

	public void deselect() {
		selected = false;
	}

	public void setCenter(Point point) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public Point getCenter() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public Integer getFrom() {
		return from;
	}

	public void setFrom(Integer from) {
		this.from = from;
	}

	public Integer getTo() {
		return to;
	}

	public void setTo(Integer to) {
		this.to = to;
	}


}
